package com.health.mapp.impl;

import java.math.BigDecimal;
import java.util.Date;

import com.health.db.model.RegisterOrder;
import com.health.db.model.RegisterOrderExample;
import com.health.db.service.order.IRegisterOrderService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.QueryLeftTimeReq;
import com.health.mapp.bean.QueryLeftTimeResp;
import com.health.mapp.utils.DateUtils;
import com.health.mapp.utils.PropertiesUtil;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/**
 *  订单查询类
 * @author HiRoad
 *
 */
public class QueryLeftTimeImpl implements ActionInterface {
	private IRegisterOrderService registerOrderService  ;
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		
		QueryLeftTimeReq req=(QueryLeftTimeReq) reqBean;
		QueryLeftTimeResp _resp= new QueryLeftTimeResp();
		
		RegisterOrderExample temp = new RegisterOrderExample();
		
		Long orderId = req.getOrderId();
		if (orderId==0 ) {
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ORDERID);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ORDERID_NOTE);
			return _resp;
		}
		
		RegisterOrder  currRegisterOrder =registerOrderService.selectSimpleSingleByOrderId(orderId);
		
		//订单错误
		if (null!=currRegisterOrder&&null!=currRegisterOrder.getOrderLeftTime()) {
			int Order_ScheduleTime_Range= Integer.valueOf(PropertiesUtil.getString("Order_ScheduleTime_Range"));
			BigDecimal leftTime =currRegisterOrder.getOrderLeftTime();
			
			//在固定时间内，才可以调用此方法
			if (!DateUtils.judgmentDateAbs(currRegisterOrder.getScheduleTime(), new Date(), Order_ScheduleTime_Range)) {
				_resp.setErrorCode(ResultCode.OPERATION_ORDER_ERROR_3007);
				_resp.setErrorMsg(ResultCode.OPERATION_ORDER_ERROR_3007_NOTE);
				return _resp;
			}
			_resp.setLeftTime(currRegisterOrder.getOrderLeftTime().intValue());
			
		}else{
			_resp.setErrorCode(ResultCode.OPERATION_ORDER_ERROR_4001);
			_resp.setErrorMsg(ResultCode.OPERATION_ORDER_ERROR_4001_NOTE);
			return _resp;
		}
		
		_resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		_resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
 
		return _resp;
	}

	public IRegisterOrderService getRegisterOrderService() {
		return registerOrderService;
	}

	public void setRegisterOrderService(IRegisterOrderService registerOrderService) {
		this.registerOrderService = registerOrderService;
	}

}
